package com.zhou.lock8;

/*
关于锁的八个问题
 */

import java.util.concurrent.TimeUnit;

public class Test1 {
    public static void main(String[] args) {
        Phone phone = new Phone();
        new Thread(()->{
            try {
                phone.sendMsg();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }, "A").start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(()->{
            phone.call();
        }, "B").start();
    }
}

class Phone{
    public synchronized void sendMsg() throws InterruptedException {
        TimeUnit.SECONDS.sleep(2);
        System.out.println("发短信!");
    }
    public synchronized void call(){
        System.out.println("打电话!");
    }
}
